<template>
	<view>
		<!-- #ifdef APP-PLUS -->
		<view>
			<uni-nav-bar left-icon="arrowleft" @clickLeft="back" title="商家申请" :statusBar='true' :fixed="true"></uni-nav-bar>
		</view>
		<!-- #endif -->
		<view class="merchant-entry">
			<view v-for="item in applys" :key="item.id" class="merchant-entry-list">
				<view class="merchant-entry-list-top">
					<text class="name">商家名称：{{ item.storeName }}</text>
					<text v-if="item.status === '0'" class="state stateColorOne">初审待审核</text>
					<text v-if="item.status === '1'" class="state stateColorTwo">初审通过</text>
					<text v-if="item.status === '2'" class="state stateColorThree">初审失败</text>
					<text v-if="item.status === '3'" class="state stateColorOne">待平台审核</text>
					<text v-if="item.status === '4'" class="state stateColorTwo">平台审核通过</text>
					<text v-if="item.status === '5'" class="state stateColorThree">平台审核失败</text>
				</view>
				<view class="merchant-entry-list-numbers">申请单号：{{ item.id }}</view>
				<view class="merchant-entry-list-time">提交时间：{{ item.createdAt }}</view>
				<view class="merchant-entry-list-btn">
					<view @click="onClickSeeBecause(item)" v-if="item.status === '2' || item.status === '5'" class="merchant-entry-list-btn-one">查看原因</view>
					<!-- <view class="merchant-entry-list-btn-two">删除</view> -->
					<view @click="onClickWSDetailInfo(item)" v-if="item.status === '1'" class="merchant-entry-list-btn-one">完善信息</view>
				</view>
			</view>
			<view class="addBtn" @click="addApply">新增提交</view>
		</view>
	</view>
</template>

<script>
	import { config } from '@/utils/config.js'
	import { myMixin } from '@/utils/mixin.js'
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue'
	export default {
		mixins: [myMixin],
		components: {
			uniNavBar
		},
		data() {
			return {
				applys: [],
				page: 1,
				size: 10,
				total: 0,
				totalPage: 0
			};
		},
		onLoad() {
			const token = uni.getStorageSync('token')
			if (!token) {
				uni.showToast({
					title: '暂无该用户凭证, 请先登录',
					icon: 'none'
				})
				setTimeout(() => {
					uni.removeStorageSync('role')
					uni.removeStorageSync('memberId')
					uni.removeStorageSync('token')
					uni.removeStorageSync('openId')
					uni.reLaunch({
						url: '../verificationcodelogin/verificationcodelogin'
					})
				}, 777)
				return false
			}
		},
		onShow() {
			this.applys = []
			this.page = 1
			this.size = 10
			this.total = 0
			this.totalPage = 0
			this.getApplys()
		},
		onReachBottom() {
			const page1 = this.page + 1
			const totalPage = this.totalPage
			if (page1 <= totalPage) {
				this.page = page1
				this.getApplys()
			} else {
				uni.showToast({
					title: '已经到底部了',
					icon: 'none'
				})
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.size = 10
			this.total = 0
			this.totalPage = 0
			this.applys = []
			this.getApplys()
		},
		methods: {
			back() {
				uni.navigateBack({})
			},
			onClickWSDetailInfo(item) {
				if (!item.id) {
					return false
				}
				uni.navigateTo({
					url: `../submitdetails/submitdetails?id=${item.id}`
				})
			},
			onClickSeeBecause(item) {
				if (item.status !== '2' && item.status !== '5') {
					return false
				}
				if (!item.remark) {
					return false
				}
				uni.showModal({
					content: item.remark,
					showCancel: false
				})
			},
			pageTotal(rowCount, pageSize) {
				if (rowCount === null || rowCount === "") {
					return 0;
				} else {
					if ((pageSize !== 0) && (rowCount % pageSize === 0)) {
						return parseInt(rowCount / pageSize)
					}
					if ((pageSize !== 0) && (rowCount % pageSize !== 0)) {
						return parseInt(rowCount / pageSize) + 1
					}
				}
			},
			getApplys() {
				uni.showLoading({ title: '加载中' })
				const page = this.page
				const size = this.size
				uni.request({
					url: `${config.api_base_url}member/merchant_apply/application/${page}/${size}`,
					header: {
						AUTH: 'ROBOT ' + uni.getStorageSync('token')
					},
					success: ((res) => {
						let { status, data } = res.data
						if (status.flag === true) {
							this.total = data.total
							this.totalPage = this.pageTotal(this.total, this.size)
							this.applys = this.applys.concat(data.rows)
						} else {
							this.total = 0
							this.totalPage = 0
							this.applys = []
						}
					}),
					fail: (() => {
						this.total = 0
						this.totalPage = 0
						this.applys = []
						uni.showToast({
							icon: 'none',
							title: '请求失败, 网络异常'
						})
					}),
					complete: (() => {
						uni.stopPullDownRefresh()
						uni.hideLoading()
					})
				});
			},
			addApply() {
				uni.navigateTo({
					url: '/pages/merchantsubmitsapply/merchantsubmitsapply'
				})
			}
		}
	};
</script>

<style>
	page {
		background: #f5f5f5;
	}
</style>
<style scoped>
	.merchant-entry {
		padding: 16rpx 16rpx;
		box-sizing: border-box;
		padding-bottom: 120rpx;
	}

	.merchant-entry-list {
		background: rgba(255, 255, 255, 1);
		box-shadow: 0 4rpx 12rpx 0 rgba(0, 0, 0, 0.05);
		border-radius: 12rpx;
		padding: 10rpx 30rpx 26rpx;
		margin-bottom: 12rpx;
	}

	.merchant-entry-list:last-child {
		margin-bottom: 0;
	}

	.merchant-entry-list-top {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 72rpx;
		border-bottom: 2rpx solid #eeeeee;
	}

	.name {
		font-size: 28rpx;
		color: #333;
		max-width: 460rpx;
		overflow: hidden;
		height: 60rpx;
		line-height: 60rpx;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.state {
		font-size: 28rpx;
	}

	.stateColorOne {
		color: #f7b500;
	}

	.stateColorTwo {
		color: #6dd400;
	}

	.stateColorThree {
		color: #ff3b30;
	}

	.merchant-entry-list-numbers {
		font-size: 28rpx;
		color: #333;
		line-height: 40rpx;
	}

	.merchant-entry-list-time {
		font-size: 28rpx;
		color: #333;
		line-height: 40rpx;
	}

	.merchant-entry-list-btn {
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding-top: 10rpx;
		box-sizing: border-box;
	}

	.merchant-entry-list-btn-one {
		padding: 0rpx 20rpx;
		box-sizing: border-box;
		height: 50rpx;
		border-radius: 12rpx;
		border: 2rpx solid rgba(0, 145, 255, 1);
		font-size: 24rpx;
		color: #0091ff;
		line-height: 50rpx;
	}

	.merchant-entry-list-btn-two {
		padding: 0rpx 20rpx;
		box-sizing: border-box;
		height: 50rpx;
		border-radius: 12rpx;
		border: 2rpx solid rgba(255, 50, 50, 1);
		font-size: 24rpx;
		color: #ff3232;
		line-height: 50rpx;
		margin-left: 16rpx;
	}


	.addBtn {
		position: fixed;
		left: 50%;
		bottom: 0;
		margin: 30rpx 0rpx;
		margin-left: -330rpx;
		width: 660rpx;
		height: 82rpx;
		background: rgba(240, 34, 48, 1);
		border-radius: 14rpx;
		font-size: 32rpx;
		color: #fff;
		text-align: center;
		line-height: 82rpx;
		margin-right: auto;
	}
</style>
